package com.example.administrator.myproject.order

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.example.administrator.myproject.R
import com.example.administrator.myproject.user.ShouAdapter

import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import com.example.administrator.myproject.bean.Collect

class CartFragment : Fragment() {
    private var recyclerView: RecyclerView? = null
    private var adapter: ShouAdapter? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.cart2, container, false)
        recyclerView = view.findViewById(R.id.cart_rv)
        recyclerView!!.layoutManager = LinearLayoutManager(activity)
        adapter = ShouAdapter(activity)
        recyclerView!!.adapter = adapter
        val query = BmobQuery<Collect>()
        query.order("-createdAt")
        query.findObjects(object : FindListener<Collect>() {
            override fun done(list: List<Collect>, e: BmobException?) {
                if (e == null) {
                    adapter!!.setData(list)
                } else {
                }
            }
        })
        return view
    }

    override fun onResume() {
        super.onResume()
        val query = BmobQuery<Collect>()
        query.order("-createdAt")
        query.findObjects(object : FindListener<Collect>() {
            override fun done(list: List<Collect>, e: BmobException?) {
                if (e == null) {
                    adapter!!.setData(list)
                } else {
                }
            }
        })
    }
}
